<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 100px;
        }
        /* 方法一 */
        .box1 {
            margin: 0 auto;
            background-color: #000;
        }
        /* 方法二 */
        .box2 {
            position: absolute;
            top: 150px;
            left: 50%;
            margin-left: -100px;
            background-color: pink;
        }
        /* 方法三 */
        .box3 {
            position: absolute;
            top: 300px;
            left: 50%;
            transform: translate(-50%);
            background-color: skyblue;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
</body>
</html>